import { FC, useState } from 'react';
import { Layout, Menu } from 'antd';
import { useNavigate, useLocation } from 'react-router-dom';
import {
  HomeOutlined,
  FileSearchOutlined,
  FileDoneOutlined,
  FileProtectOutlined,
} from '@ant-design/icons';
import styles from './SideMenu.module.css';

const { Sider } = Layout;

const SideMenu: FC = () => {
  const navigate = useNavigate();
  const location = useLocation();
  
  // 设置默认展开的菜单
  const defaultOpenKeys = ['pre-acceptance', 'formal-acceptance', 'summary'];
  const [openKeys, setOpenKeys] = useState<string[]>(defaultOpenKeys);

  // 保持菜单展开状态 
  const handleOpenChange = (keys: string[]) => {
    setOpenKeys(keys);
  };

  const menuItems = [
    {
      key: '/home',
      icon: <HomeOutlined />,
      label: '首页'
    },
    {
      key: 'pre-acceptance',
      icon: <FileSearchOutlined />,
      label: '档案预验收',
      children: [
        { key: '/pre-acceptance', label: '验收申请' },
        { key: '/pre-acceptance/notice', label: '验收通知' },
        { key: '/pre-acceptance/process', label: '验收过程' },
        { key: '/pre-acceptance/feedback', label: '问题反馈' }
      ]
    },
    {
      key: 'formal-acceptance',
      icon: <FileDoneOutlined />,
      label: '正式验收',
      children: [
        { key: '/formal-acceptance', label: '验收申请' },
        { key: '/formal-acceptance/notice', label: '验收通知' },
        { key: '/formal-acceptance/material', label: '材料管理' },
        { key: '/formal-acceptance/process', label: '验收过程' },
        { key: '/formal-acceptance/reform', label: '整改复查' }
      ]
    },
    {
      key: 'summary',
      icon: <FileProtectOutlined />,
      label: '总结备案',
      children: [
        { key: '/summary/reform', label: '整改确认' },
        { key: '/summary/filing', label: '结果备案' }
      ]
    }
  ];

  return (
    <Sider width={200} className={styles.sider}>
      <Menu
        mode="inline"
        selectedKeys={[location.pathname]}
        openKeys={openKeys}
        onOpenChange={handleOpenChange}
        items={menuItems}
        onClick={({ key }) => navigate(key)}
      />
    </Sider>
  );
};

export default SideMenu; 